//
//  SetAddOrEditKindKeys.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 2016/11/11.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "SetAddOrEditKindKeys.h"
#import "EditModel.h"
#import "EducationAdminClient_URL.h"

@implementation SetAddOrEditKindKeys

+ (void)dataUse:(id)obj andTnum:(NSInteger )_tNum andtString:(NSString *)_tString andButtonDic:(NSDictionary *)buttonDic  andReturnBlock:(void(^)(NSMutableDictionary *sendDic, NSMutableArray *manyArr, NSDictionary *buttonDic, NSMutableArray *hiddenArr, NSMutableArray *textFieldArr))cb{
    [self dataUse:obj andTnum:_tNum andtString:_tString andButtonDic:buttonDic andReturnBlock:cb];
}
- (void)dataUse:(id)obj andTnum:(NSInteger )_tNum andtString:(NSString *)_tString andButtonDic:(NSDictionary *)buttonDic  andReturnBlock:(void(^)(NSMutableDictionary *sendDic, NSMutableArray *manyArr, NSDictionary *buttonDic, NSMutableArray *hiddenArr, NSMutableArray *textFieldArr, NSMutableArray *fieldArr))cb{

    _filedArr = [[NSMutableArray alloc]init];
    _conditionShow = [[NSMutableArray alloc]init];
    _needElseChange = [[NSMutableArray alloc]init];
    _sendMutDic = [[NSMutableDictionary alloc]init];
    _mangManArr = [[NSMutableArray alloc]init];
    _buttonDic = [[NSMutableDictionary alloc]initWithDictionary:buttonDic];
    _hiddenArr = [[NSMutableArray alloc]init];
    _textFieldArr = [[NSMutableArray alloc]init];
    
        //***jsonModel 数据处理 , 如果键值对有所改变 ， 那么就将 model 内的 内容进行更改，注意 使用时的问题 ， cellForrowInThePath
        //    _conditionShow = [[NSMutableArray alloc]init];
        
        if([obj objectForKey:@"pageSet"]){
            
            self.relationId = [NSString stringWithFormat:@"%@", [[obj objectForKey:@"pageSet"] valueForKey:@"relationFieldId"]]; // 将关联添加的 relationId 取出来 ， 如果要是关联添加的话，就可以直接使用关联添加的Id
            
            NSArray *dataArr = [[obj objectForKey:@"pageSet"]valueForKey:@"fieldSet"];
            for (NSDictionary *dic in dataArr) {
                EditModel *model = [[EditModel alloc]init];
                model = [model initWithDictionary:dic error:nil];
                NSString *modelDefaultValueChange = [NSString stringWithFormat:@"%@", model.fieldRole];
                //             NSString *modelDefaultValueChange = [NSString stringWithFormat:@"%@", model.ifShowDefVal];wewe
                
                NSString *stringUpdate = [NSString stringWithFormat:@"%@", model.ifUpdate];
                NSString *stringDefault = [NSString stringWithFormat:@"%@", model.dicDefaultSelect];
                
                // 数据字典类型
                if ([modelDefaultValueChange isEqualToString:@"16"]&&![stringUpdate isEqualToString:@"0"]&&stringDefault.length>0) {
                    
                    model.true_defaultShowValName = model.dicDefaultSelect;
                }
                [_filedArr addObject:model];
                if (model.jsWhereStr) { // 查看是否有启用禁用条件
                    [_conditionShow addObject:model];
                }
                if (model.tmpFieldId) {
                    [_needElseChange addObject:model];
                }
                
                
                
                
                NSString *fieldRole =[NSString stringWithFormat:@"%@", model.fieldRole];
                NSInteger num =[fieldRole integerValue];
                // 拼接上传值
                if(num == 20 || num == 21 || num == 22){// 弹层 下拉树 内部对象
                    
                    //                [self whileFieldRowTypeIsspeciall:model];
                    
                    [_keyValueClass whileFieldRowTypeIsspeciall:model andTnum:_tNum andTstring:_tString andSendMutDic:_sendMutDic andManyMan:_mangManArr andEditDetailDic:_buttonDic andReturnBlock:^(NSMutableDictionary *send, NSMutableArray *manyman, NSDictionary *dicDEdit, EditModel *model){
                        _sendMutDic = send;
                        _mangManArr = manyman;
                        _buttonDic = (NSMutableDictionary *)dicDEdit;
                    }];
                }else if(num == 14||num==28||num==26|| num == 15){ // 时间格式的 使用 14 年月日 ， 15 时分秒
                    //                NSDateFormatter *formate = [[NSDateFormatter alloc]init];
                    if(num == 15){
                        model.dateType = TIMEFORMATE;
                    }else{
                        model.dateType = DATEFORMATE;
                    }
                    if(model.true_defaultShowValName&&[model.true_defaultShowValName hasSuffix:@"000"]){
                        model.true_defaultShowValName = [KeyValuesClass dateGlinToFormate:model.true_defaultShowValName andFromate:model.dateType]; // 由于时间格式返回的都是  格林尼治 所以 ····
                        [_sendMutDic setObject:model.true_defaultShowValName forKey:model.montageName];
                        
                    }else if(model.true_defaultShowValName){
                        //model.true_defaultShowValName = [KeyValuesClass dateGlinToFormate:model.true_defaultShowValName andFromate:model.dateType]; // 由于时间格式返回的都是  格林尼治 所以 ····
                        [_sendMutDic setObject:model.true_defaultShowValName forKey:model.montageName];
                    }else{
                        [_sendMutDic setObject:@"" forKey:model.montageName];
                    }
                    
                    
                }else if(num!=-1){
                    
                    if(model.true_defaultShowValName){
                        [_sendMutDic setObject:model.true_defaultShowValName forKey:model.montageName];
                    }else{
                        [_sendMutDic setObject:@"" forKey:model.montageName];
                    }
                    
                }else if(num == -1){ // 占位 以防出现更多的 -1 状况
                    NSString *strTimeDefault = [NSString stringWithFormat:@"%@", model.true_defaultShowValName];// 时间格式下找出web端是以 000 为结尾的格式显示 ， 在未找出 更合适的 方式之前 暂时用这个方式
                    
                    if([strTimeDefault hasSuffix:@"000"]){
                        if(model.true_defaultShowValName){
                            model.true_defaultShowValName = [KeyValuesClass dateGlinToFormate:model.true_defaultShowValName andFromate:model.dateType]; // 由于时间格式返回的都是  格林尼治 所以 ····
                            
                        }
                        
                    }
                }
                
                //*** 必填项存储
                NSString *mustStr = [NSString stringWithFormat:@"%@",model.ifMust];
                if( [mustStr isEqualToString:@"1"]){
                    [_textFieldArr addObject:model];
                }
            }
            NSArray *arrHiddenText = [[obj objectForKey:@"pageSet"]valueForKey:@"hideFieldSet"];
            
            for (NSDictionary *dic in arrHiddenText) {
                EditModel *model = [[EditModel alloc]init];
                model = [model initWithDictionary:dic error:nil];
                [_hiddenArr addObject:model];
            }
            
            
        }


    cb(_sendMutDic, _mangManArr, _buttonDic, _hiddenArr, _textFieldArr, _filedArr);

}
@end
